package com.cy.pojo;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReentrantReadWriteLock;

/**
 * Created by PVer on 2017/8/8.
 */
public class RedisLock extends ReentrantReadWriteLock{
    public static boolean kaiguan = true;
    private String key;
    private AtomicInteger useNum;

    public RedisLock(String key) {
        this.key = key;
        this.useNum = new AtomicInteger(1);
    }

    public RedisLock(boolean fair) {
        super(fair);
        this.useNum = new AtomicInteger(1);
    }

    public ReentrantReadWriteLock.WriteLock writeLock() {
        if (kaiguan) {
            return super.writeLock();
        } else {
            return null;
        }
    }

    public int addNum(int i) {
        return this.useNum.addAndGet(i);
    }

    public int showNum() {
        return this.useNum.get();
    }

    public String getKey() {
        return this.key;
    }

    public void setKey(String key) {
        this.key = key;
    }
}
